
#include<Windows.h>
#include <iostream>
#include "../mem_op2/mem_util.h"

using namespace std;

void f(char a[],char b[20]){
    cout << "a=" << sizeof(a) << endl;
    cout << "b=" << sizeof(b) << endl;
}


unsigned char code[] = {
    0x55,                           /* push ebp */
    0x89, 0xE5,                     /* mov ebp, esp */
    0x83, 0xEC, 0x08,               /* sub esp, 8 */
    0x68, 0x00, 0x00, 0x00, 0x00,   /* push 地址，这里需要修改 */
    0x6A, 0x00,                     /* push 0 */
    0xE8, 0x00, 0x00, 0x00, 0x00,   /* call printf 函数地址，这里需要修改 */
    0x83, 0xC4, 0x08,               /* add esp, 8 */
    0x89, 0xEC,                     /* mov esp, ebp */
    0x5D,                           /* pop ebp */
    0xC3                            /* ret */
};


int main()
{
    cout << "Hello World!" << endl;

//    cout << "input process ID: " << endl;
//    DWORD processId;
//    cin >> processId;

    wchar_t cmd[] = L"cmd.exe";

    xy::OtherProcess p(cmd);

    cout <<"process id: " << p.get_process_id() << endl;

    xy::OtherProcessMemory pm(&p);
//    unsigned char d[100];

//    cout << "read num of bytes:" << pm.read((LPVOID)0x10000,d,100) << endl;
//    d[99] = 0;
//    cout << "out read data:" << d << endl;

//    char a[100] = "AAAAA";
//    a[99] = 0;
//    cout <<"a=" << a << " sizeof(a)="<< sizeof(a) <<endl;

//    cout<<pm.write((LPVOID)0x10000,a,100)<<endl;

//    char c[] = "ABC!@#123";

//    f(c,c);

    LPVOID s = pm.alloc(sizeof (code));

    cout << pm.write(s,code,sizeof (code)) << endl;
    xy::RemoteThread t(&p,(LPTHREAD_START_ROUTINE)s);
    t.start();

    t.wait();


    getchar();


    return 0;
}
